// pages/mine/repair/repairDetail/repairDetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:null, // 1: 未处理 2：已处理 3：已完成
    repairId:null,

    images:[],
    remark:"无",
    title:"",
    room_number:"",
    createTime:"",

    headImg:"../../../../images/default_avatar.png",

    user:{},
    records:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({ 
      type:options.type || null,
      repairId:options.id || null,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.showDetail()
  },
  /**
   * 页面显示
   */
  showDetail(){
    app.globalData.request("get","applet/repair/repairDetails",{
      repair_id: this.data.repairId,
      id:wx.getStorageSync("id")
    })
    .then(res => {
      console.log(res)
      this.setData({
        title: res.data.title,
        room_number: res.data.room_number,
        createTime: res.data.create_time,
        images: res.data.image,
        remark: res.data.remark,
        user: res.data.user,
        records: res.data.records
      })
    }).catch(err => {
      console.log(err)
    })
  },
  /**
   * 编辑和重新提交
   */
  submit(e){
    wx.navigateTo({
      url: '../repairSubmit/repairSubmit?type=' + e.currentTarget.dataset.type +'&id='+this.data.repairId,
    })
  },
  /**
   * 联系维修工
   */
  contract(){
    wx.makePhoneCall({
      phoneNumber: this.data.user.admin_tel,
    })
  }
})